<%# locals: remark, topic, type %>
<%# append remark in under a topic, used in topics/remark %>

<%# remark (no type, topic) %>
<%# append remark in under a topic, used in topics/remark & remarks/*.js.erb %>

<%# rewritting with helper! %>

<% topic = remark.topic %>

<% hidden_style = false %>
<% if remark.new_record? %>
  <div id=<%= raw "topic_append_remark_#{topic.id}" %>>
<% else %>
  <%# TODO rewrite any? method %>
  <% if remark.errors.any? %>
    <div id=<%= raw "remark_edit_#{remark.id}" %>>
  <% else %>
    <div style="display:none" id=<%= raw "remark_edit_#{remark.id}" %>>
  <% end %>
<% end %>

  <p>回复：
    <%= remark_reply_tag(remark) %>
    <% if !remark.parent_remark.nil? %>
      <% if remark.new_record? && !remark.parent_remark.nil? %>
        <%= cancel_reply_tag_a(remark) %>
        <%# if it's not a new record, parent_record should not be changable. %>
        <%# cancel_reply_tag_a('取消', remark) %>
      <% end %>
    <% end %>
  </p>

  <% if remark.new_record? %>
    <% form_id = "topic_append_remark_form_#{topic.id}" %>
  <% else %>
    <% fomr_id = "remark_form_#{remark.id}" %>
  <% end %>
  
  <%= form_for remark, remote: true, html: { id: form_id } do |f| %>

    <%# hidden fields %>
    <% if remark.new_record? %>
      <%= remark_topic_id_tag(remark) %>
      <%= remark_operation_on_topic_tag(remark) %>
      <%= remark_parent_remark_id_tag(remark) %>
    <% end %>
    <%= remark_remark_type_question_tag(remark) %>
    
    <% if topic_type(remark.topic) == :question %>
      <p>普通评论 | 修改意见 | 修改确认</p>
        <% if !remark.question_version.nil? %>
          <%= render partial: 'question_versions/form', 
              locals: { question_version: remark.question_version } %>
        <% end %>
      <hr />
    <% end %>

    <%= render partial: 'remarks/fields', locals: { f: f } %>
    <%= f.submit '提交' %>
    <% if remark.new_record? %>
    <%# TODO cancel button %>
    <% else %>
    <%= button_tag '取消', type: 'button', onClick: "close_edit('remark','#{remark.id}')" %>
    <% end %>
  <% end %>
</div>
